/**
 * chenxitech.cn Inc.
 * Copyright (c) 2017-2017 All Rights Reserved.
 */
package com.zsc.common.web.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 日志打印规范类
 *
 * @author xbkaishui
 * @version $Id: PrintLogUtil.java, v 0.1 2017-04-12 下午10:24 xbkaishui Exp $$
 */
public class PrintLogUtil {
    private static final char SPLIT = '|';
    private static final Logger logger = LoggerFactory.getLogger(PrintLogUtil.class);

    public static void logOperation(Logger LOGGER, String resourceName, String operationMode, String operationResult) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("ResourceName:{}|OperationMode:{}|OperationResult:{}", resourceName, operationMode, operationResult);
        }
    }

    public static void info(Logger LOGGER, Object... msg) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(getLogString(msg));
        }
    }

    public static void info(Logger LOGGER, String msg) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(msg);
        }
    }

    public static void info(Logger LOGGER, String format, Object... arguments) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(format, arguments);
        }
    }

    public static void debug(Logger LOGGER, String format, Object... arguments) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(format, arguments);
        }
    }

    public static void debug(Logger LOGGER, Object... msg) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(getLogString(msg));
        }
    }

    public static void debug(Logger LOGGER, String msg) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(msg);
        }
    }


    public static void warn(Logger LOGGER, String msg) {
        LOGGER.warn(msg);
    }

    public static void error(Logger LOGGER, String msg, Throwable ex) {
        LOGGER.error(msg, ex);
    }

    public static void error(Logger LOGGER, Throwable ex) {
        error(LOGGER, ex.getMessage(), ex);
    }

    public static String getLogString(Object... msgs) {
        StringBuilder log = new StringBuilder();
        for (Object o : msgs) {
            log.append(o);
            log.append(SPLIT);
        }
        //delete last split
        if (log.length() > 0) {
            log.deleteCharAt(log.length() - 1);
        }
        return log.toString();
    }

}
